package core.config;


import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;

@Configuration
public class EsConfig {
    @Bean
    public RestHighLevelClient restHighLevelClient() {
       /* RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(
                new HttpHost("localhost", 9200, "http")));
        return client;*/

        return RestClients.create(ClientConfiguration.create("172.16.17.40")).rest();
    }

    /**
     * ElasticsearchTemplate已经废弃，建议用ElasticsearchRestTemplate
     * 创建ElasticsearchRestTemplate需要RestHighLevelClient对象
     *
     * @return
     */
    @Bean
    public ElasticsearchRestTemplate elasticsearchRestTemplate() {
        ElasticsearchRestTemplate template = new ElasticsearchRestTemplate(restHighLevelClient());
        return template;
    }
}
